
export function pad (n) {
  return String(n > 9 ? n : '0' + n)
}


/**
 * Number format
 *
 * @param {number} n
 * @param {number} l: length of decimal
 * @param {number} x: length of sections
 */
function format (n, l, x) {
  if (!n) {
    return ''
  }
  var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (l > 0 ? '\\.' : '$') + ')'
  return n.toFixed(Math.max(0, ~~l)).replace(new RegExp(re, 'g'), '$&,')
}

export function sign (n) {
  return n > 0 ? '+' + n : n
}

export default {
  format,
  sign,
  pad
}
